function calc(l,r:longint):longint;
var sum:longint;
begin
sum:=0;
while l<=r do begin
  if l mod 2=1 then begin
    inc(sum,a[l]);
    inc(l);
  end;
  if r mod 2=0 then begin
    inc(sum,a[r]);
    dec(r);
  end;
  l:=l div 2;
  r:=r div 2;
end;
result:=sum;
end;

procedure add(i,k:longint);
begin
inc(i,pow(2,n)-1);
while i>=1 do begin
  inc(a[i],k);
  i:=i div 2;
end;
end;